home *** CD-ROM | disk | FTP | other *** search
/ Power Programmierung 2 / Power-Programmierung CD 2 (Tewi)(1994).iso / c / library / bcfamily / source / vesabios.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  1993-06-12  |  3.1 KB  |  130 lines

  1. //
  2. //      *******************************************************************
  3. //        JdeBP C++ Library Routines          General Public Licence v1.00
  4. //            Copyright (c) 1991,1992     Jonathan de Boyne Pollard
  5. //      *******************************************************************
  6. //
  7. // Part of FamAPI.LIB
  8. //
  9.  
  10. #include "famapi.h"
  11. #include "vio.h"
  12.  
  13. #pragma saveregs
  14. //
  15. //    Return the current screen mode and number of columns
  16. //
  17. USHORT _APICALL
  18. VioDosScreenMode ( void )
  19. {
  20.     _AH = 0x0f ;
  21.     geninterrupt(0x10) ;
  22.     return _AX ;
  23. }
  24.  
  25. #pragma saveregs
  26. //
  27. //    Return the current cursor position (Row << 8) + Col ;
  28. //
  29. USHORT _APICALL
  30. VioDosGetCurPos ( void )
  31. {
  32.     _AX = 0x0300 ;
  33.     _BH = 0 ;
  34.     geninterrupt(0x10) ;
  35.     return _DX ;
  36. }
  37.  
  38. #pragma saveregs
  39. //
  40. //    Set the current cursor position (Row << 8) + Col ;
  41. //
  42. void _APICALL
  43. VioDosSetCurPos ( unsigned short pos )
  44. {
  45.     _AX = 0x0200 ;
  46.     _BH = 0 ;
  47.     _DX = pos ;
  48.     geninterrupt(0x10) ;
  49. }
  50.  
  51. struct VESAModeInfo {
  52.     WORD ModeAttributes ;
  53.     BYTE WinAAttribtes ;
  54.     BYTE WinBAttribtes ;
  55.     WORD WinGranularity ;
  56.     WORD WinSize ;
  57.     WORD WinASegment ;
  58.     WORD WinBSegment ;
  59.     LONG WinFuncPtr ;
  60.     WORD BytesPerScanLine ;
  61.  
  62.     // Optional, provided if ModeAttributes & 0x0002 is true
  63.  
  64.     WORD XResolution ;
  65.     WORD YResolution ;
  66.     BYTE XCharSize ;
  67.     BYTE YCharSize ;
  68.     BYTE NumberOfPlanes ;
  69.     BYTE BitePerPixel ;
  70.     BYTE NumberOfBanks ;
  71.     BYTE MemoryModel ;
  72.     BYTE BankSize ;
  73.     BYTE NumberOfImagePages ;
  74.     BYTE Reserved ;
  75.     BYTE Reserved2[225] ;
  76. } ;
  77.  
  78. //
  79. //    Construct a far pointer to text memory, or return 0:0 for graphics mode
  80. //
  81. unsigned short far * _APICALL
  82. VioDosPointer    ( unsigned short Row,
  83.                   unsigned short Col )
  84. {
  85.     unsigned short mode = VioDosScreenMode () ;
  86.     unsigned short width = mode >> 8 ;
  87.     unsigned short seg ;
  88.  
  89.     mode &= 0xFF ;
  90.  
  91.     //
  92.     //    Modes are excluded from SVGA processing if they *only* represent
  93.     //    text modes.  Some VGA modes may be either text or graphics modes
  94.     //    according to the make of VGA BIOS.  In which case we check for
  95.     //    Super VGA, and if it is not present, we force the BIOS calls to be
  96.     //    used instead of direct-to-memory.
  97.     //
  98.     if ( (mode&0x7F) > 0x03 && (mode&0x7F) != 0x07 &&
  99.         mode != 0x2a && mode != 0x4d && mode != 0x4e && mode != 0x4f ) {
  100.         static struct VESAModeInfo far SVGABuf ;
  101.  
  102.         //
  103.         //    Test for SVGA BIOS
  104.         //
  105.         _AX = 0x4F03 ;                        // Return current VESA mode
  106.         geninterrupt(0x10) ;
  107.         if (_AL != 0x4F || _AH != 0x00)        // Unsupported, or call failed
  108.             return (unsigned short far *)MK_FP(0, 0) ;
  109.  
  110.         _CX = _BX ;                            // Video mode
  111.         _ES = FP_SEG(&SVGABuf) ;
  112.         _DI = FP_OFF(&SVGABuf) ;
  113.         _AX = 0x4F01 ;                        // Return VESA mode information
  114.         if (_AL != 0x4F || _AH != 0x00)        // Unsupported, or call failed
  115.             return (unsigned short far *)MK_FP(0, 0) ;
  116.  
  117.         if ( SVGABuf.ModeAttributes & 0x0010 )
  118.             return (unsigned short far *)MK_FP(0, 0) ;    // Graphics mode
  119.  
  120.         if ( SVGABuf.ModeAttributes & 0x0002 )    // Extended information
  121.             width = SVGABuf.XResolution ;
  122.  
  123.         seg = 0xB800 ;
  124.  
  125.     } else
  126.  
  127.         seg = ((mode&0x7F) == 0x07) ? 0xB000 : 0xB800 ;
  128.  
  129.     return (unsigned short far *)MK_FP(seg, ( (Row * width) + Col ) << 1 ) ;
  130. }